home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9997 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  32 lines

  1. Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
  2. Path: cwi.nl!dik
  3. From: dik@cwi.nl (Dik T. Winter)
  4. Subject: Re: Access carry flag from C
  5. Message-ID: <Dnssxu.JGy@cwi.nl>
  6. Sender: news@cwi.nl (The Daily Dross)
  7. Nntp-Posting-Host: chrysant.cwi.nl
  8. Organization: CWI, Amsterdam
  9. References: <4h1veoINNlns@anvil.ugrad.cs.ubc.ca> <fgrieu-0403961143580001@ppp78.micronet.fr> <4hhbt8$1d3o@b.stat.purdue.edu>
  10. Date: Tue, 5 Mar 1996 14:15:29 GMT
  11.  
  12. In article <4hhbt8$1d3o@b.stat.purdue.edu> hrubin@b.stat.purdue.edu (Herman Rubin) writes:
  13.  > In article <fgrieu-0403961143580001@ppp78.micronet.fr>,
  14.  > Franτois Grieu <fgrieu@micronet.fr> wrote:
  15.  > 
  16.  > >   if (x + yl < yl) ++yh; /* test for overflow on next line */
  17.  > >   yl += x;
  18. ...
  19.  > Notice that in the above code, each addition must be performed twice.
  20.  
  21. Wrong.  Even a mediocre compiler will optimize this away.
  22.  
  23.  > BTW, there is a weakness in the code; ++yh can cause a carry, so
  24.  > another test is needed.  As testing is expensive, what is needed in
  25.  > this case is not a test for carry, but the ability to add the carry
  26.  > bit to something.
  27.  
  28. But the code above also works on machines without carry bit.
  29. -- 
  30. dik t. winter, cwi, kruislaan 413, 1098 sj  amsterdam, nederland, +31205924098
  31. home: bovenover 215, 1025 jn  amsterdam, nederland; http://www.cwi.nl/~dik/
  32.